home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacOS 8 Resources / Developer Tools / Mac OS 8 Interfaces & Libraries / Interfaces / PInterfaces / Synchronization.p < prev    next >
Text File  |  1996-05-01  |  7KB  |  159 lines

  1. {
  2.      File:        Synchronization.p
  3.  
  4.      Contains:    Synchronization Interfaces
  5.  
  6.      Version:    Technology:    System 8
  7.                  Release:    Universal Interfaces 3.0d3 on Copland DR1
  8.  
  9.      Copyright:    © 1984-1996 by Apple Computer, Inc.  All rights reserved.
  10.  
  11.      Bugs?:        If you find a problem with this file, send the file and version
  12.                  information (from above) and the problem description to:
  13.  
  14.                      Internet:    apple.bugs@applelink.apple.com
  15.                      AppleLink:    APPLE.BUGS
  16.  
  17. }
  18. {$IFC UNDEFINED UsingIncludes}
  19. {$SETC UsingIncludes := 0}
  20. {$ENDC}
  21.  
  22. {$IFC NOT UsingIncludes}
  23.  UNIT Synchronization;
  24.  INTERFACE
  25. {$ENDC}
  26.  
  27. {$IFC UNDEFINED __SYNCHRONIZATION__}
  28. {$SETC __SYNCHRONIZATION__ := 1}
  29.  
  30. {$I+}
  31. {$SETC SynchronizationIncludes := UsingIncludes}
  32. {$SETC UsingIncludes := 1}
  33.  
  34. {$IFC UNDEFINED __TYPES__}
  35. {$I Types.p}
  36. {$ENDC}
  37. {$IFC UNDEFINED __KERNEL__}
  38. {$I Kernel.p}
  39. {$ENDC}
  40.  
  41. {$PUSH}
  42. {$ALIGN POWER}
  43. {$LibExport+}
  44.  
  45. {$IFC FOR_SYSTEM8_PREEMPTIVE }
  46. {  Note:  Lock, ReadWriteLock, and CountingSemaphore data structures must be LONG WORD ALIGNED in memory! }
  47.  
  48. TYPE
  49.     LockPtr = ^Lock;
  50.     Lock = RECORD
  51.         theInfo:                ARRAY [0..1] OF UInt32;
  52.     END;
  53.  
  54.     ReadWriteLockPtr = ^ReadWriteLock;
  55.     ReadWriteLock = RECORD
  56.         theInfo:                ARRAY [0..4] OF UInt32;
  57.     END;
  58.  
  59.     CountingSemaphorePtr = ^CountingSemaphore;
  60.     CountingSemaphore = RECORD
  61.         theInfo:                ARRAY [0..5] OF UInt32;
  62.     END;
  63.  
  64.     LockOptions                            = OptionBits;
  65.  
  66. CONST
  67.     kLockDisablesSwis            = $00000001;                    {  disable software interrupts while locked }
  68.     kLockAdjustsPriorities        = $00000002;                    {  lock prevents priority inversion }
  69.     kLockDisablesCompletionRoutines = $00000004;                {  disable software interrupts and system 7 completion routines while locked }
  70.  
  71.  
  72. TYPE
  73.     InterruptState                        = Ptr;
  74. {
  75.  Simple lock routines
  76.  Locks may be created with the kLockDisablesSwis and/or kLockDisablesCompletionRoutines options,
  77.  but no others.
  78. }
  79. FUNCTION CreateLock(VAR theLock: Lock; theOptions: LockOptions): OSStatus; C;
  80. FUNCTION DeleteLock(VAR theLock: Lock): OSStatus; C;
  81. FUNCTION BeginLockedSection(VAR theLock: Lock): OSStatus; C;
  82. FUNCTION TryBeginLockedSection(VAR theLock: Lock): OSStatus; C;
  83. FUNCTION EndLockedSection(VAR theLock: Lock): OSStatus; C;
  84. FUNCTION IsLockedSectionHeld(VAR theLock: Lock): BOOLEAN; C;
  85. {
  86.  Reader/writer lock routines
  87.  ReadWriteLocks may be created with the kLockDisablesSwis, kLockDisablesCompletionRoutines,
  88.  and/or kLockAdjustsPriorities options.
  89. }
  90. FUNCTION CreateReadWriteLock(VAR theReadWriteLock: ReadWriteLock; theOptions: LockOptions): OSStatus; C;
  91. FUNCTION DeleteReadWriteLock(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
  92. FUNCTION BeginReadLockedSection(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
  93. FUNCTION TryBeginReadLockedSection(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
  94. FUNCTION EndReadLockedSection(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
  95. FUNCTION BeginWriteLockedSection(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
  96. FUNCTION TryBeginWriteLockedSection(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
  97. FUNCTION EndWriteLockedSection(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
  98. FUNCTION ChangeWriteLockToReadLock(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
  99. FUNCTION IsReadLockedSectionHeld(VAR theReadWriteLock: ReadWriteLock): BOOLEAN; C;
  100. FUNCTION IsWriteLockedSectionHeld(VAR theReadWriteLock: ReadWriteLock): BOOLEAN; C;
  101. FUNCTION GetReadWriteLockReaderCount(VAR theReadWriteLock: ReadWriteLock): ItemCount; C;
  102. FUNCTION GetReadWriteLockWriterID(VAR theReadWriteLock: ReadWriteLock): TaskID; C;
  103. {
  104.  Counting semaphore routines
  105.  CountingSemaphores currently have no options.
  106. }
  107. FUNCTION CreateCountingSemaphore(VAR theCountingSemaphore: CountingSemaphore; theOptions: LockOptions; initialCount: SInt32; maximumCount: SInt32): OSStatus; C;
  108. FUNCTION DeleteCountingSemaphore(VAR theCountingSemaphore: CountingSemaphore): OSStatus; C;
  109. FUNCTION WaitForCountingSemaphore(VAR theCountingSemaphore: CountingSemaphore): OSStatus; C;
  110. FUNCTION SignalCountingSemaphore(VAR theCountingSemaphore: CountingSemaphore): OSStatus; C;
  111. FUNCTION GetCountingSemaphoreCount(VAR theCountingSemaphore: CountingSemaphore): SInt32; C;
  112. FUNCTION GetCountingSemaphoreMaxCount(VAR theCountingSemaphore: CountingSemaphore): SInt32; C;
  113. FUNCTION GetCountingSemaphoreWaiterCount(VAR theCountingSemaphore: CountingSemaphore): ItemCount; C;
  114. {
  115.  Interrupt enabling and disabling.  ** MAY ONLY BE CALLED FROM PRIVILEGED CODE!!! **
  116.  Use very sparingly.
  117. }
  118. FUNCTION DisableInterrupts: InterruptState; C;
  119. PROCEDURE RestoreInterrupts(theState: InterruptState); C;
  120. {
  121.  Atomic operations on 8-, 16-, and 32-bit entities.
  122.  ** OPERATIONS THAT CROSS WORD (32-BIT) BOUNDARIES WILL FAIL!!! **
  123. }
  124. FUNCTION CompareAndSwapAligned(oldValue: UInt32; newValue: UInt32; VAR theValue: UInt32): BOOLEAN; C;
  125. {  Note: TestAndSet uses PPC bit ordering, zero is the high bit, and theBit ranges from 0 - FFFFFFFF. }
  126. FUNCTION TestAndSet(theBit: UInt32; VAR startAddress: UInt8): BOOLEAN; C;
  127. FUNCTION IncrementAtomic8(VAR value: SInt8): SInt8; C;
  128. FUNCTION DecrementAtomic8(VAR value: SInt8): SInt8; C;
  129. FUNCTION AddAtomic8(amount: SInt32; VAR value: SInt8): SInt8; C;
  130. FUNCTION BitAndAtomic8(mask: UInt32; VAR value: UInt8): ByteParameter; C;
  131. FUNCTION BitOrAtomic8(mask: UInt32; VAR value: UInt8): ByteParameter; C;
  132. FUNCTION BitXorAtomic8(mask: UInt32; VAR value: UInt8): ByteParameter; C;
  133. FUNCTION IncrementAtomic16Aligned(VAR theValue: SInt16): SInt16; C;
  134. FUNCTION DecrementAtomic16Aligned(VAR theValue: SInt16): SInt16; C;
  135. FUNCTION AddAtomic16Aligned(theAmount: SInt32; VAR theValue: SInt16): SInt16; C;
  136. FUNCTION BitAndAtomic16Aligned(theMask: UInt32; VAR theValue: UInt16): UInt16; C;
  137. FUNCTION BitOrAtomic16Aligned(theMask: UInt32; VAR theValue: UInt16): UInt16; C;
  138. FUNCTION BitXorAtomic16Aligned(theMask: UInt32; VAR theValue: UInt16): UInt16; C;
  139. FUNCTION IncrementAtomicAligned(VAR theValue: SInt32): SInt32; C;
  140. FUNCTION DecrementAtomicAligned(VAR theValue: SInt32): SInt32; C;
  141. FUNCTION AddAtomicAligned(theAmount: SInt32; VAR theValue: SInt32): SInt32; C;
  142. FUNCTION BitAndAtomicAligned(theMask: UInt32; VAR theValue: UInt32): UInt32; C;
  143. FUNCTION BitOrAtomicAligned(theMask: UInt32; VAR theValue: UInt32): UInt32; C;
  144. FUNCTION BitXorAtomicAligned(theMask: UInt32; VAR theValue: UInt32): UInt32; C;
  145. {  Atomic primitives for singly linked list manipulation. }
  146. PROCEDURE PushListElementAtomic(theListHead: UNIV Ptr; theListElement: UNIV Ptr; theLinkOffset: UInt32); C;
  147. FUNCTION PopListElementAtomic(theListHead: UNIV Ptr; theLinkOffset: UInt32): Ptr; C;
  148. {$ENDC}
  149. {$ALIGN RESET}
  150. {$POP}
  151.  
  152. {$SETC UsingIncludes := SynchronizationIncludes}
  153.  
  154. {$ENDC} {__SYNCHRONIZATION__}
  155.  
  156. {$IFC NOT UsingIncludes}
  157.  END.
  158. {$ENDC}
  159.